<template>
	<view>
		<view class="g-user">
			<text>昵称:</text>
			<text>{{user.nickName}}</text>

			<view>头像:</view>
			<image :src="url+user.avatar" mode=""></image>
		</view>

		<button class="m-btn" type="default" @click="bindLogout">退出登录</button>

	</view>
</template>

<script>
	import {
		baseURL
	} from '../../api/requestUtil'
	export default {
		data() {
			return {
				user: {},
				url:baseURL
			}
		},
		methods: {
			bindUserInfo() {
				const token = uni.getStorageSync('token') // 获取保存的token值
				console.log('token ', token);
				uni.request({
					url: baseURL + '/prod-api/api/common/user/getInfo',
					method: 'GET',
					header: {
						"Authorization": token
					}
				}).then(res => {
					console.log('res >> ', res);
					const data = res.data
					if (data.code == 200) {
						this.user = data.user
					}
				})
			},
			bindLogout(){
				uni.removeStorageSync('token')
				uni.redirectTo({
					url:'/pages/login/login'
				})
			}
		},
		// 页加载生命周期
		onLoad() {
			this.bindUserInfo()
		}
	}
</script>

<style scoped>
	.m-btn {
		width: 70%;
		margin-top: 40px;
	}
</style>